package com.gy.springboot.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gy.springboot.service.TestService;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    JdbcTemplate jdbcTemplate;

    @RequestMapping("/hello")
    public String helloWorld(String str) {
        System.out.println("----------------" + str);
        return "hello world";
    }

    @RequestMapping("/add")
    public Long addTwoNumber(Integer a, Integer b) {
        System.out.println(a + "+" + b + "result is: " + (a + b));
        return testService.addTwoNumber(a, b);
    }

    @RequestMapping("/user/login")
    public String userLogin(HttpSession session) {
        session.setAttribute("loginUser", "already");
        return "login success";
    }

    @RequestMapping("find/data/test")
    public String findNameById(Integer id) {
        List<Map<String, Object>> list = jdbcTemplate
                .queryForList("select name from user_test where id= " + id);
        return list.get(0).get("name").toString();
    }

}
